package com.ruoyi.project.management.delay.controller;

import com.ruoyi.common.utils.security.ShiroUtils;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.framework.web.page.TableDataInfo;
import com.ruoyi.project.management.delay.domain.TaskDelay;
import com.ruoyi.project.management.delay.mapper.ManagementTaskMapper;
import com.ruoyi.project.management.delay.service.ManagementDelayService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.List;

@Controller
@RequestMapping("/management/delay")
public class ManagementDelayController extends BaseController {


    private String prefix = "management/delay";

    @Autowired
    private ManagementDelayService managementDelayService;





    /**
     * 跳转到任务延期
     * @return
     */
    @GetMapping()
    public String task()
    {
        return prefix + "/delay";
    }

    /**
     * 更具条件分页查询
     * @param delay 条件
     * @return
     */
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(TaskDelay delay)
    {
        startPage();
        List<TaskDelay> list = managementDelayService.selectMore(delay);
        return getDataTable(list);
    }

    /**
     * 校验延迟任务id是否唯一并且存在
     */
    @PostMapping("/checkDelayTaskIdUnique")
    @ResponseBody
    public String checkDelayTaskIdUnique(TaskDelay delay)
    {
        return managementDelayService.checkDelayTaskIdUnique(delay);
    }

    /**
     * 新增延期任务
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }


    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(TaskDelay taskDelay)
    {
        taskDelay.setApproved_by("董事长");
        taskDelay.setPass(0);
        return toAjax(managementDelayService.insert(taskDelay));
    }

    /**
     * 修改任务
     */
    @GetMapping("/edit/{delay_Id}")
    public String edit(@PathVariable("delay_Id") Integer delay_Id, ModelMap mmap)
    {
        mmap.put("delay", managementDelayService.selectDelayById(delay_Id));
        return prefix + "/edit";
    }

    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(TaskDelay taskDelay)
    {
        System.out.println(taskDelay);





        return toAjax(managementDelayService.update(taskDelay));
    }


    /**
     * 根据延期id查看任务信息
     * @param
     * @param mmap
     * @return
     */
    @GetMapping("/detail/{delay_Id}")
    public String show(@PathVariable("delay_Id") Integer delay_Id, ModelMap mmap)
    {
        mmap.put("delay", managementDelayService.selectDelayById(delay_Id));
        return prefix + "/show";
    }



   // 删除
    @PostMapping("/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        try
        {
            return toAjax(managementDelayService.delete(ids));
        }
        catch (Exception e)
        {
            return error(e.getMessage());
        }
    }













}
